<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>添加商品-azhuo商城</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

	<link href="${pageContext.request.contextPath }/css/bksystem.css" rel="stylesheet" type="text/css" />
	<link href="${pageContext.request.contextPath }/css/module.css" rel="stylesheet" type="text/css" />
	<link href="${pageContext.request.contextPath }/css/loaders.css" rel="stylesheet" type="text/css" />
	<link href="${pageContext.request.contextPath }/skin/black/skin.css" rel="stylesheet" type="text/css" id="skin" />
	<link href="${pageContext.request.contextPath }/fonts/iconfont.css" rel="stylesheet" type="text/css" />

	<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/lib/layui/layui.js" charset="utf-8"></script>
	<script>
		$(document).ready(function () {
			// 加载分类
			loadCategory();

		});

		// 使用ajax从数据库加载分类
		function loadCategory() {
			$.ajax({
				type: "POST",// 请求的方式默认为get 改为Post
				url: "${pageContext.request.contextPath}/admin/AdminCategoryServlet",// 往服务器端请求的地址 写成绝对路径
				data: {
					method: "loadCategory"
				},// 往服务器端发送的数据
				// 接受服务器端数据函数 回调函数
				success: function (data) {
					// data是服务器返回的数据
					console.log("data =" + data);
					if (data) {
						addCategoryInSelect(data);
					}
				}
			});
		}

		// 把json字符串中的数据添加到select选项中
		function addCategoryInSelect(jsonData) {
			var jsonArr = eval(jsonData);

			$.each(jsonArr, function (key, value) {

				var option = '<option value="' + value.cid + '">' + value.cname + '</option>';
				console.log("option = " + option);
				$("#category").append(option);
			});
		}
	</script>

</head>

<body>
	<div class="tab-box tabcontent">
		<div class="tab-conent prompt_style active">
			<form action="${pageContext.request.contextPath }/admin/AdminAddGoodsServlet" method="post"
				enctype="multipart/form-data" class="layui-form">
				<ul class="clearfix add_style" style="padding-left: 20px; padding-top: 20px;">
					<li class="cell-item">
						<label class="cell-left label_name">商品名称:</label>
						<div class="cell-right">
							<input name="gname" type="text" class="col-xs-6 col-lg-12" />
						</div>
					</li>
					<li class="cell-item">
						<label class="cell-left label_name">商品价格:</label>
						<div class="cell-right">
							<input name="price" type="text" class="col-xs-6 col-lg-12" />
						</div>
					</li>
					<li class="cell-item">
						<label class="cell-left label_name">商品图片:</label>
						<div class="cell-right">
							<input name="image" type="file" class="col-xs-6 col-lg-12" style="width: 200px" />
							<span style="color: #f00;size: 30px">${msg }</span>
						</div>

					</li>
					<li class="cell-item">
						<label class="cell-left label_name">商品所属分类:</label>
						<div class="cell-right">
							<select name="cid" id="category">
								<option selected="selected" value="">请选择商品分类</option>
							</select>
						</div>
					</li>
					<li class="cell-item">
						<label class="cell-left label_name">商品参数:</label>
						<div class="cell-right">
							<input name="parameter" type="text" class="col-xs-6 col-lg-12" />
						</div>
					</li>
					<li class="cell-item">
						<label class="cell-left label_name">宣传商品类型:</label>
						<div class="cell-right">
							<input type="radio" name="promote" id="p0" value="0" checked="checked" />
							<label for="p0" style="padding-right: 20px;">默认</label>
							<input type="radio" name="promote" id="p1" value="1" />
							<label for="p1" style="padding-right: 20px;">轮播图</label>
							<input type="radio" name="promote" id="p2" value="2" />
							<label for="p2" style="padding-right: 20px;">热销商品</label>
							<input type="radio" name="promote" id="p3" value="3" />
							<label for="p3" style="padding-right: 20px;">推荐商品</label>
						</div>
					</li>
					<li class="cell-item">
						<label class="cell-left label_name">商品描述:</label>
						<div class="cell-right">
							<input name="desc" type="text" class="col-xs-6 col-lg-12" />
						</div>
					</li>
				</ul>
				<div class="buttonstyle"  style="padding-left: 200px;">
					<input type="submit" class="btn padding10 bg-deep-blue" value="添加商品" />
					<!-- <a href="javascript:" title="添加商品" class="btn padding10 bg-deep-blue">添加</a> -->
				</div>
			</form>
		</div>
		<div class="tab-conent prompt_style ">

		</div>
		<div class="tab-conent prompt_style ">

		</div>
	</div>
</body>

</html>